﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.EntityFrameworkCore;
using OABackground.Entities;
namespace OABackground.Infrastructure
{
    public class AwardPunishRepository
    {
        #region 奖惩申请表增删改查函数
        public void Add(Awardpunish Awardpunishlist)//添加一个申请表项
        {

            using (oaContext dbContext = new oaContext())
            {

                dbContext.Awardpunish.Add(Awardpunishlist);//这不是真的添加
                dbContext.SaveChanges();//用“保存”表示一次事务的完成
            }
        }
        public void Update(Awardpunish Awardpunishlist)//更新奖惩申请表信息
        {
            using (var dbContext = new oaContext())
            {
                dbContext.Update(Awardpunishlist);
                dbContext.SaveChanges();
            }
        }
        public Awardpunish Query(string Id)//查找单条奖惩申请信息
        {

            using (var dbContext = new oaContext())
            {
                var select = dbContext.Awardpunish.Find(Id);
                dbContext.SaveChanges();
                return select;
            }
        }
        public Student QueryStudentById(string id)//查找单条奖惩申请信息
        {
            Student student = null;
            using (var context = new oaContext())
            {
                student = context.Student.FirstOrDefault(x => x.Id == id);
                context.SaveChanges();
            }
            return student;
        }
        public List<Awardpunish> QueryAll()//查询全部奖惩
        {
            List<Awardpunish> AwardPunishlist = new List<Awardpunish>();
            using (var dbcontext = new oaContext())
            {
                AwardPunishlist = (from u in dbcontext.Awardpunish
                                   select u
                            ).ToList();
                dbcontext.SaveChanges();

                return AwardPunishlist;
            }
        }
        public void Delete(string Id)//删除单条奖惩申请信息
        {
            using (var dbContext = new oaContext())
            {
                var select = dbContext.Awardpunish.Find(Id);
                dbContext.Remove(select);
                dbContext.SaveChanges();
            }

        }
        #endregion

    }
}
